package com.junsi.controller;
import java.util.List;


import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.junsi.bean.CompactGenre;

import com.junsi.service.CompactGenreService;

/**
 * 合同类型控制器
 * @author lenovo
 *
 */
@Controller
@RequestMapping("/compactGenre")
public class CompactGenreController {
	@Autowired
	private CompactGenreService compactGenreService;
	Logger logger=Logger.getRootLogger();

	/**
	 * 新增
	 */
	@RequestMapping("/insert")
	public ModelAndView insert(CompactGenre compactGenre, HttpServletResponse response) throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		compactGenreService.insert(compactGenre);
		modelAndView.setViewName("redirect:/compactGenre/select.action");
		return modelAndView;
	}

	/**
	 * 刪除
	 */
	@RequestMapping("/deletes")
	public ModelAndView deletes(Integer id, HttpServletResponse response) {
	     compactGenreService.delete(id);
	 	ModelAndView modelAndView = new ModelAndView();
	 	modelAndView.setViewName("redirect:/compactGenre/select.action");
		return modelAndView;
	
	}

	/**
	 * 更新
	 * 
	 * @throws Exception
	 */
	@RequestMapping("/updata")
	public ModelAndView updata(CompactGenre compactGenre, HttpServletResponse response) throws Exception {
		  compactGenreService.update(compactGenre);
			ModelAndView modelAndView = new ModelAndView();
		 	modelAndView.setViewName("redirect:/compactGenre/select.action");
			return modelAndView;		
	}

	/**
	 * 查詢
	 * 
	 * @throws Exception
	 */
	@RequestMapping("/select")
	public ModelAndView select(HttpServletResponse response) throws Exception {
		ModelAndView modelAndView=new ModelAndView();
		List<CompactGenre> list = compactGenreService.listAll();
		  modelAndView.addObject("list", list);
	      modelAndView.setViewName("forward:/page/hetong.jsp");
	      return modelAndView;
	}
}
